<#assign className = table.className>
${gg.setOverride(true)}
package ${basepackage}.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.zy.ems.common.base.BaseEntity;

public class ${className}Entity extends BaseEntity {
    private static final long serialVersionUID = 1L;

    <#list table.columns as column>
    <#if column.isDateTimeColumn>
    public static final String FORMAT_${column.constantName} = DATE_FORMAT;
    </#if>
    </#list>

    <#list table.columns as column>
    /**
     * ${column.columnAlias!}(db_column: ${column.sqlName})
     */
    private ${column.possibleShortJavaType} ${column.columnNameLower};

    </#list>

<@generateEntityConstructor className/>
<@generateJavaColumns/>
<@generateJavaOneToMany/>
<@generateJavaManyToOne/>

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
        <#list table.columns as column>
            .append("${column.columnName}", get${column.columnName}())
        </#list>
            .toString();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder()
        <#list table.pkColumns as column>
            .append(get${column.columnName}())
        </#list>
            .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof ${className}Entity)) {
            return false;
        }
        if(this == obj) {
            return true;
        }
        ${className}Entity other = (${className}Entity) obj;
        return new EqualsBuilder()
            <#list table.pkColumns as column>
            .append(get${column.columnName}(), other.get${column.columnName}())
            </#list>
            .isEquals();
    }
}

<#macro generateEntityConstructor constructor>
    public ${constructor}Entity(){
    }

    public ${constructor}Entity(
            <#list table.compositeIdColumns as column>
            ${column.possibleShortJavaType} ${column.columnNameLower}<#if column_has_next>,</#if>
            </#list>        
            ){
        <#list table.compositeIdColumns as column>
        <#if column.pk>
        this.${column.columnNameLower} = ${column.columnNameLower};
        </#if>
        </#list>    
    }

</#macro>

<#macro generateJavaColumns>
    <#list table.columns as column>
        <#if column.isDateTimeColumn>
    public String get${column.columnName}String() {
        return DateConvertUtils.format(get${column.columnName}(), FORMAT_${column.constantName});
    }
    public void set${column.columnName}String(String value) {
        set${column.columnName}(DateConvertUtils.parse(value, FORMAT_${column.constantName},${column.possibleShortJavaType}.class));
    }
        </#if>

    public ${column.possibleShortJavaType} get${column.columnName}() {
        return this.${column.columnNameLower};
    }

    public void set${column.columnName}(${column.possibleShortJavaType} value) {
        this.${column.columnNameLower} = value;
    }
    </#list>
</#macro>

<#macro generateJavaOneToMany>
    <#list table.exportedKeys.associatedTables?values as foreignKey>
    <#assign fkSqlTable = foreignKey.sqlTable>
    <#assign fkTable    = fkSqlTable.className>
    <#assign fkPojoClass = fkSqlTable.className>
    <#assign fkPojoClassVar = fkPojoClass?uncap_first>

    private Set ${fkPojoClassVar}s = new HashSet(0);

    public Set<${fkPojoClass}Entity> get${fkPojoClass}s() {
        return this.${fkPojoClassVar}s;
    }

    public void set${fkPojoClass}s(Set<${fkPojoClass}Entity> ${fkPojoClassVar}){
        this.${fkPojoClassVar}s = ${fkPojoClassVar};
    }
    </#list>
</#macro>

<#macro generateJavaManyToOne>
    <#list table.importedKeys.associatedTables?values as foreignKey>
    <#assign fkSqlTable = foreignKey.sqlTable>
    <#assign fkTable    = fkSqlTable.className>
    <#assign fkPojoClass = fkSqlTable.className>
    <#assign fkPojoClassVar = fkPojoClass?uncap_first>

    private ${fkPojoClass}Entity ${fkPojoClassVar};

    public ${fkPojoClass}Entity get${fkPojoClass}() {
        return this.${fkPojoClassVar};
    }

    public void set${fkPojoClass}(${fkPojoClass}Entity ${fkPojoClassVar}){
        this.${fkPojoClassVar} = ${fkPojoClassVar};
    }
    </#list>
</#macro>
